Skip to content

perf: Optimize the convert_value method and reuse it#5166

Merged
shaohuzhang1 merged 5 commits into1Panel-dev:v2from
wangliang181230:PR/perf-convert_value
Apr 27, 2026
Merged

perf: Optimize the convert_value method and reuse it#5166
shaohuzhang1 merged 5 commits into1Panel-dev:v2from
wangliang181230:PR/perf-convert_value

Conversation

@wangliang181230
Copy link
Copy Markdown
Contributor

@wangliang181230 wangliang181230 commented Apr 24, 2026

What this PR does / why we need it?

Optimize the convert_value method and reuse it

Summary of your change

优化 convert_value 方法:

  1. _typedictarray 时,先判断 value 是否已经是该类型并直接return,避免报错。
  2. 将该方法添加到 common.py 中共用

Please indicate you've done the following:

  • Made sure tests are passing and test coverage is added if needed.
  • Made sure commit message follow the rule of Conventional Commits specification.
  • Considered the docs impact and opened a new docs issue or PR with docs changes if needed.

@f2c-ci-robot
Copy link
Copy Markdown

f2c-ci-robot Bot commented Apr 24, 2026

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@f2c-ci-robot
Copy link
Copy Markdown

f2c-ci-robot Bot commented Apr 24, 2026

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@wangliang181230 wangliang181230 changed the title perf: Optimize the convert_value method perf: Optimize the convert_value method and reuse it Apr 24, 2026
return float(value)
if _type == 'dict':
if isinstance(value, dict):
return value
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

value 已经是 dict 时,直接 return,否则 json.loads(value) 会报错

raise Exception(_('type error'))
if _type == 'array':
if isinstance(value, list):
return value
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

value 已经是 list 时,直接 return,否则 json.loads(value) 会报错

for item in source_value:
if str(item) == target_value:
return True
return False
Copy link
Copy Markdown
Contributor Author

@wangliang181230 wangliang181230 Apr 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为 list 时,性能优化了下,原来的写法,需要list中所有元素都比较一遍后才进行 any 方法。

for item in source_value:
if str(item) == target_value:
return False
return True
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上:为 list 时,性能优化了下。

@shaohuzhang1 shaohuzhang1 merged commit a6ed82f into 1Panel-dev:v2 Apr 27, 2026
1 of 2 checks passed
@wangliang181230 wangliang181230 deleted the PR/perf-convert_value branch April 27, 2026 04:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants